/**
 * 
 */
package com.mas.session.state;

import com.mas.session.Session;
import com.mas.strategey.Proposal;
import com.thoughtworks.xstream.XStream;

import jade.lang.acl.ACLMessage;

/**
 * this class represents the automaton state: create counter proposal
 * 
 * @author Elad Ben Ami
 * 
 */
public class CreateCounterProposal extends AbstractState {

	public CreateCounterProposal(Session session) {
		super(session);
	}

	/**
	 * calls to strategy for creating new proposal and send.
	 * 
	 * @param message
	 */
	public void offerNewProposal(ACLMessage message) {

		Proposal newPorposal = session.getStrategy().buildNewProposal(proposal);

		ACLMessage replyMessage = message.createReply();
		XStream xstream = new XStream();
		replyMessage.setContent(xstream.toXML(newPorposal));
		replyMessage.setPerformative(ACLMessage.PROPOSE);

		this.session.getAgent().send(replyMessage);

		WaitingForProposalResState state = (WaitingForProposalResState) this.session
				.assignState(WaitingForProposalResState.class.getName());
		session.setCurrentState(state);
		state.setProposal(newPorposal);
		state.waitForProposalResponse(message);
	}

}
